package com.yutel.shell;

public class TestExec {
	public static void main(String args[]) {
		String cmd = "ping 192.168.2.243 -c 40";
		exec("pwd");
		//exec(cmd);
	}
	public static void exec(String cmd) {
		try {
			
			Runtime rt = Runtime.getRuntime();
			Process proc = rt.exec(cmd);
			// any error message
			StreamGobbler errorGobbler = new StreamGobbler(
					proc.getErrorStream(), "ERR");
			// any output
			StreamGobbler outputGobbler = new StreamGobbler(
					proc.getInputStream(), "OUT");
			// kick them off
			errorGobbler.start();
			outputGobbler.start();
			// any error
			int exitVal = proc.waitFor();
			System.out.println("ExitValue: " + exitVal);
			errorGobbler.join();
			outputGobbler.join();
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}
}
